﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PB.Airsoft.Business.Shop.Entities;
using PB.Airsoft.Business.Item;
using PB.Airsoft.Business.Shop.Interfaces;
using PB.Airsoft.Business.Item.Interfaces;
using PB.Airsoft.Business.Shop;
using PB.Airsoft.Web.Business;

namespace PB.Airsoft.Web.city.controls
{
    public partial class ShopLotControl : System.Web.UI.UserControl
    {
        public IShopLot ShopLot
        {
            get { return (IShopLot)ViewState["ShopLot"]; }
            set { ViewState["ShopLot"] = value; }
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (this.ShopLot == null)
                return;

            var item = ItemManager.GetItem(this.ShopLot.ItemId);
            this.lblItemName.Text = item.Name;
            this.lblItemDescription.Text = item.Description;
            this.lblPrice.Text = this.ShopLot.Price.ToString();
            this.btnBuy.Enabled = this.ShopLot.Price <= AppContext.Current.User.Money;
        }

        protected void btnBuy_Click(object sender, EventArgs e)
        {
            if (this.ShopLot.Price <= AppContext.Current.User.Money)
                ShopManager.Buy(this.ShopLot.Id, AppContext.Current.User.Id);
        }
    }
}